$(function(){
	var c = document.getElementById("c"),
			ctx = c.getContext("2d");
	
	c.width = innerWidth;
	c.height = innerHeight;
	
	var lines = [],
			maxSpeed = 10,
			spacing = 10,
			xSpacing = 0,
			n = innerWidth / spacing,
			colors = ["#ffffff", "#FAAA48", "#000A5C", "#6B6B6B"],
			i;
	
	for (i = 0; i < n; i++){
		xSpacing += spacing;
		lines.push({
			x: xSpacing,
			y: Math.round(Math.random()*c.height),
			width: 2,
			height: Math.round(Math.random()*(innerHeight/18)),
			speed: Math.random()*2,
			color: colors[Math.floor(Math.random() * colors.length)]
		});
	}
	
	
	function draw(){
		var i;
		ctx.clearRect(0,0,c.width,c.height);
		
		for (i = 0; i < n; i++){
			ctx.fillStyle = lines[i].color;
			ctx.fillRect(lines[i].x, lines[i].y, lines[i].width, lines[i].height);
			lines[i].y += lines[i].speed;
			
			if (lines[i].y > c.height)
				lines[i].y = 0 - lines[i].height;
		}
		
		requestAnimationFrame(draw);
		
	}
	
	draw();
	
}());
    //添加窗口尺寸改变响应监听
$(function() {
	$(window).resize(resizeCanvas);
        //页面加载后先设置一下canvas大小
        resizeCanvas();
      });
 
      //窗口尺寸改变响应（修改canvas大小）
  function resizeCanvas() {
    $("#myCanvas").attr("width", $(window).get(0).innerWidth);
    $("#myCanvas").attr("height", $(window).get(0).innerHeight);
      };